package com.jf.cloud.product.feign;



import com.jf.cloud.api.product.feign.SkuStockFeignClient;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.product.service.SkuStockService;
import com.jf.cloud.product.service.SpuExtensionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Hidden;

/**
 * @author zz
 * @date 2022/11/17 15:29
 */
@RestController
@Hidden
public class SkuStockFeignController implements SkuStockFeignClient {
    @Autowired
    private SkuStockService skuStockService;

    @Autowired
    private SpuExtensionService spuExtensionService;
    @Override
    public ServerResponseEntity<Integer> getBySkuId(Long skuId) {
        return ServerResponseEntity.success(skuStockService.getBySkuId(skuId).getStock());
    }

    @Override
    public ServerResponseEntity<Integer> getTotalStockBySpuId(Long spuId) {
        Integer totalStock = skuStockService.getTotalBySpuId(spuId);
//        // 没有分片就按原方式获取
//        if (Objects.isNull(totalStock)) {
//            SpuExtension spuExtension = spuExtensionService.getBySpuId(spuId);
//            totalStock = spuExtension.getStock();
//        }
        return ServerResponseEntity.success(totalStock);
    }
}
